home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / crc.swg / 0002_File CHECKSUM.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  88 lines

  1. {nice Program/utility which can be used to check the 'sorted' File and the data
  2. File. It produces the Byte CheckSum of the Files (which must be identical), and
  3. can check the sortorder of the File (when given the option -s)...
  4. }
  5. {$A+,B-,D-,F-,G+,I-,L-,N-,O-,R-,S+,V-,X-}
  6. {$M 16384,0,655360}
  7. { Here is the Program CHECKSUM that you can run to check the master data
  8.   File For TeeCee's String sorting contest. if you have a slow machine I
  9.   suggest you set the Program running and go to bed!! :-)
  10.  
  11.   Code size: 5952 Bytes
  12.   Data size:  924 Bytes
  13.   .EXE size: 6304 Bytes
  14. }
  15. Uses Crt;
  16. Const
  17.   Version = 'CheckSum 1.0 (c) 1992 DwarFools & Consultancy, '+
  18.                                   'by drs. Robert E. Swart'#13#10;
  19.   Usage = 'Usage: CheckSum dataFile [-s]'#13#10 +
  20.    '       Options: -s to check the sortorder of the Strings'#13#10;
  21.   MaxStr = 30;
  22.   Error: LongInt = 0;
  23.   Records: LongInt = 0;
  24.   CheckSum: Byte = 0;   { Byte CheckSum of all Bytes in data File xor'ed }
  25.   Sortorder: Boolean = False;            { Assume option -s is not given }
  26.  
  27. Var Str: String[MaxStr];
  28.     len: Byte Absolute Str;
  29.     ByteStr: Array[0..MaxStr] of Byte Absolute Str;
  30.     PrevStr,UpperStr: String[MaxStr];
  31.     f: File;
  32.     i: Integer;
  33.  
  34. begin
  35.   Writeln(Version);
  36.   if ParamCount = 0 then
  37.   begin
  38.     Writeln(Usage);
  39.     Halt
  40.   end;
  41.  
  42.   assign(f,ParamStr(1)); { Change this to your chosen File name }
  43.   reset(f,1);
  44.   if Ioresult <> 0 then
  45.   begin
  46.     Writeln('Error: could not open ',ParamStr(1));
  47.     Writeln(Usage);
  48.     Halt(1)
  49.   end;
  50.  
  51.   if (ParamCount = 2) and
  52.     ((ParamStr(2) = '-s') or (ParamStr(2) = '-S')) then Sortorder := True;
  53.  
  54.   Writeln('Strings x 1000 checked:');
  55.   While not eof(f) do
  56.   begin
  57.     BlockRead(f,len,1);
  58.     BlockRead(f,Str[1],len);
  59.     For i:=0 to len do CheckSum := CheckSum xor ByteStr[i];
  60.     if Sortorder then
  61.     begin
  62.       UpperStr[0] := Str[0];
  63.       For i:=1 to len do UpperStr[i] := UpCase(Str[i]);
  64.       if Records > 0 then
  65.       begin
  66.         if PrevStr > UpperStr then
  67.         begin
  68.           Inc(Error);
  69.           Writeln;
  70.           Writeln('Error: ',PrevStr,' > ',UpperStr);
  71.         end;
  72.         PrevStr := UpperStr
  73.       end
  74.     end;
  75.     Inc(Records);
  76.     if (Records mod 1000) = 0 then
  77.     begin
  78.       GotoXY(1,WhereY);
  79.       Write(Records div 1000:3);
  80.     end
  81.   end;
  82.   close(f);
  83.   Writeln;
  84.   Write(Records,' Strings checked, ');
  85.   if Sortorder then Writeln(Error,' Errors found, ');
  86.   Writeln('Byte CheckSum = ',CheckSum)
  87. end.
  88.